/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lt.cj.core.server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lt.cj.config.entities.ConfigModel;
import org.lt.cj.config.util.MissionBuilder;
import org.lt.cj.core.server.entity.RequestTask;

/*
 * @author luohong
 */
public class ClientSocket implements IPostRequestTask {

    ObjectOutputStream clientOutputStream = null;
    ObjectInputStream clientInputStream = null;

    public void postRequestTask(ConfigModel configModel) {

        try {
            RequestTask task = new RequestTask();
            task.setConfigModel(configModel);
            task.setUsername("boling");
            task.setPassword("%$#ltoop123");
            Socket socketConnection = new Socket("127.0.0.1", 3027);
            clientOutputStream = new ObjectOutputStream(socketConnection.getOutputStream());
            clientOutputStream.writeObject(task);
        } catch (Exception ex) {
        } finally {
            try {
                clientOutputStream.close();
            } catch (IOException ex) {
                Logger.getLogger(ClientSocket.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void postTask() {

        try {
            MissionBuilder builder = new MissionBuilder();
            ConfigModel configModel = builder.buildTaoBaoMission();
            RequestTask task = new RequestTask();
            task.setConfigModel(configModel);
            task.setUsername("boling");
            task.setPassword("%$#ltoop123");
            Socket socketConnection = new Socket("127.0.0.1", 4001);
            clientOutputStream = new ObjectOutputStream(socketConnection.getOutputStream());
            clientOutputStream.writeObject(task);
            clientOutputStream.close();
        } catch (Exception ex) {
        }
    }

    public static void main(String[] args) {

        ClientSocket socket = new ClientSocket();
        socket.postTask();
    }
}
